const Service = require('egg').Service;
class XueService extends Service {
    async getindex() {
        try {
            //模糊查询
            await ctx.model.TableName.findAll({ where: { title: { $like: `%${keywords}%` } } });
            let data = await this.app.model.Xue.findAll();
            return {
                code: '200',
                msg: '成功',
                data: data,
            };
        } catch (e) {
            return {
                code: '401',
                msg: '获取失败',
                data: e,
            }
        }
    }
    async getcreate() {
        try {
            let list = this.ctx.request.body;
            await this.app.model.Xue.create({
                name: list.name,
                chengji: list.chengji,
                clazzId: list.id
            })
            let data = await this.app.model.Xue.findAll();
            return {
                code: '200',
                msg: '成功',
                data: data,
            };
        } catch (e) {
            return {
                code: '402',
                msg: '添加失败',
            }
        }
    }
    async getdestroy(id) {
        try {
            await this.app.model.Xue.destroy({ where: { id: id } });
            let data = await this.app.model.Xue.findAll();
            return {
                code: '200',
                msg: '成功',
                data: data,
            };
        } catch (e) {
            return {
                code: '403',
                msg: '删除失败',
            }
        }
    }
}

module.exports = XueService;